#ifndef _SCN_H
#define _SCN_H

#if C2504
#pragma message("Scene.h")
#endif

#include "D3D11Client.h"
#include "D3D11Effect.h"

class D3D11Client;

class CelBackground;

struct DISPLAY_TEXTURE_VERTEX
{
    float x, y, z, w;
    float tu, tv;
};

class Scene {
    friend class D3D11Client;
    friend class D3D11Pad;
    friend class TextureMgr;

public:
//init:
    Scene(D3D11Client *pGC);
    ~Scene();
    void Init3D();
    void InitStatics();
    void InitObjects();
    void Exit3D();

//matrixes:
    D3DXMATRIX *GetVP()        {    return &ViewProj;    }

    D3DXMATRIX *GetV()        {    return &View;        }
    D3DXMATRIX *GetP()        {    return &Proj;        }

//misc:
    double GetCamAperture()    {    return CamAperture;    }
    float GetAspect()        {    return Aspect;        }
    OBJHANDLE GetProxyBody(){    return Proxy;        }
    VECTOR3 GetCamPos() const        {    return CamPos_new;        }
    float GetFarPlane()        {    return far_plane;    }
    DWORD GetBgColor()        {    return bg_rgba;        }
    D3DXVECTOR3 *GetAmbientColor()    {    return &cBackground;    }
    DWORD GetPlanetariumFlag()    {    return PlanetariumFlag;    }

    TextureMgr * GetTextureMgr();
    inline D3D11Client * GetClient() { return mGraphicsClient; }

    float GetLuminance();

//rendering:
    void Render_0();
    void SaveParams();
    void Render_1();
    void Update();    

//checks visibility of a bounding sphere
    float vh, vw;
    float vhf, vwf;
    D3DXVECTOR3 camera_x;
    D3DXVECTOR3 camera_y;
    D3DXVECTOR3 camera_z;
    bool IsVisibleInCamera( D3DXVECTOR3 *vec, float rad );
    bool IsVisiblePoint( D3DXVECTOR3 *vec );

    void SetRenderTarget();

private:
    void InitGlobalVars();
    void DeleteGlobalVars();

    DWORD BBDrawCount;

//managers:
    CelBackground *mCelBkgrnd;

//texture buffers:
    IDXGISurface1
        *PBuffer_Surf;
    ID3D11Texture2D
        *BackBuffer,
        *RTarget,
        *PBuffer;
    ID3D11RenderTargetView
        *BackBuffer_RTV,
        *RTarget_RTV,
        *PBuffer_RTV;
    ID3D11ShaderResourceView
        *RTarget_SRV,
        *PBuffer_SRV;
    ID3D11DepthStencilView
        *RTarget_DSV;
//states:
//    ID3D11DepthStencilState
//        *DSS_NoDepth_NoStencil;        //planets, stars, markers, 2D, etc.
    //    *DSS_FlatShadows;            //base & vessel shadows
    //    *DSS_Vessels;                //vessels
//vars:
    WORD PBuffers_counter;    //not needed ?
    OBJHANDLE
        Proxy,        //proxy GBody [current frame]
        Proxy_new;    //proxy GBody [new frame]
    float
        Aspect,        //width/heigth of window
        near_plane,    //camera's near plane [1.0 def]
        far_plane;    //camera's far plane [1e6 def]
    double
        CamAperture,
        CamAperture_new;            //obtained through oapiCameraAperture()
    D3DXMATRIX
        ViewProj_VC, ViewProj_VC_new,
        View, Proj, ViewProj,
        View_new, Proj_new, ViewProj_new;
    VECTOR3
        CamPos,        //[current frame]
        CamPos_new;    //[next frame]
    D3DXVECTOR3    cBackground;//sky color float4
    DWORD bg_rgba;            //sky color DWORD
    double    dSkyBrt;        //sky brightness
    int BgLvl;                //background level
    DWORD PlanetariumFlag;    //current planetarium mode



    //2D Sketchpad
    D3D11Pad *pSketch;
    COLORREF LabelCol[6];
    oapi::Pen
        *LabelPen[6],
        *NullPen;
    oapi::Font
        *LabelFont,
        *DebugFont;
    oapi::Brush
        *DebugBrush;

    //debug string
    char debug_str[256];
    int debug_len;

    D3D11Client *mGraphicsClient;
};

#endif
